package C_java类库新特性.Stream;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author 赵超
 * @e-mail 18701321850@163.com
 * @description 创建Stream
 * @createTime 2017/10/3 - 15:24.
 */
public class CreateStream {
    public static void main(String[] args) {
//        createByArrays().forEach(System.out::println);
//        createByCollect().forEach(System.out::println);
//        createByValues().forEach(System.out::println);
        createByFile();
    }

    private static Stream<String> createByArrays() {
        String[] strs = {"789", "213", "sa", "mk", "asv", "1po"};
//        return Arrays.asList(strs).stream();
        return Arrays.stream(strs);
    }

    private static Stream<String> createByCollect() {
        List<String> list = Arrays.asList("2","4","as","11","d");
        return list.stream();
    }

    private static Stream<String> createByValues() {
        return Stream.of("daa", "swa", "11", "AsC", "osq");
    }

    private static Stream<String> createByFile() {
        Path path = Paths.get("D:\\WorkSpaces\\Workspace_Idea-2015\\Java8NewProperties\\src\\C_java类库新特性\\Stream\\Streams.java");
        try (Stream<String> lines = Files.lines(path)) {
            lines.forEach(System.out::println);
            return lines;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
